package com.along.game.action.manage;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.along.framework.utils.FgConstant;
import com.along.framework.utils.PatinationUtil;
import com.along.framework.utils.ReqFuncs;
import com.along.framework.web.BaseAction;
import com.along.game.model.Gamescene;
import com.along.game.service.BaseInfoService;

public class GameSceneAction extends BaseAction {
	private static final long serialVersionUID = -6840177094159940804L;
	@Autowired
	private BaseInfoService baseInfoService;

private Gamescene gameSceneVO;
private Map if_using =new LinkedHashMap(); 
public Map getIf_using() {
	return FgConstant.IF_USING;
}


public void setIf_using(Map if_using) {
	this.if_using = if_using;
}



public Gamescene getGameSceneVO() {
	return gameSceneVO;
}


public void setGameSceneVO(Gamescene gameSceneVO) {
	this.gameSceneVO = gameSceneVO;
}


/**
 * 查询场景/房间列表
 */
public String queryGamescene()
{
       HttpServletRequest request=getRequest();
		String currentpage=request.getParameter("currentpage");
        int  totalRows =baseInfoService.queryGameSceneCount(gameSceneVO);
		currentpage=PatinationUtil.getCurrentPage(currentpage);
		int startrow=PatinationUtil.getStartRow(currentpage);
		int endrow=PatinationUtil.getEndRow(currentpage);
		List gameSceneList =baseInfoService.queryGameScene(startrow, endrow, gameSceneVO);
		currentpage=PatinationUtil.getCurrentPage(currentpage);
        request.setAttribute("totalRows", totalRows);
		request.setAttribute("currentpage", currentpage);
		request.setAttribute("gameSceneList", gameSceneList);

return "/baseinfo/gamescenelist.jsp";
}


/**
 * 进入场景/房间修改页
 */
public String editGamescene()
{
       HttpServletRequest request=getRequest();
	
		
		
		 if(gameSceneVO!=null&&gameSceneVO.getFiledId()!=null)
		  {
			  request.setAttribute("addorupdate", "update");
			  gameSceneVO=baseInfoService.queryGameSceneDetail(String.valueOf(gameSceneVO.getFiledId()));
			
		  }
		  else{
	
			  request.setAttribute("addorupdate", "add");
		  }
			 
		
			
return "/baseinfo/gamesceneedit.jsp";
}



/**
 * 执行修改和增加场景/房间信息
 * @return
 * @throws IOException 
 * @throws BusException
 */
public String postGamescene() throws IOException{


 HttpServletRequest request=getRequest();
HttpServletResponse response=getResponse();
String addorupdate=request.getParameter("addorupdate");
	String message="";
	if(addorupdate.equals("add"))
	{
		baseInfoService.loadGameScene(gameSceneVO);
			message="场景/房间信息配置成功";
			
	}
	else if(addorupdate.equals("update"))
	{
	
		baseInfoService.saveGameScene(gameSceneVO);
			message="场景/房间信息修改成功";
	
		
	}
	else  if(addorupdate.equals("remove")){

		baseInfoService.removeGameScene(String.valueOf(gameSceneVO.getFiledId()));
	
	
	message="场景/房间信息删除成功";
	}
	 response.setContentType("text/html;charset=UTF-8");
	response.getWriter().println("<script>alert('"+message+"');this.location.href='gameScene_queryGamescene.do';</script>");
	response.flushBuffer();
	  return  null;

	//JSONUtil.writerJSON(list, response.getWriter(),java.util.Date.class);

}





}
